import os

def getfilesize(filepath):
    """计算文件夹实际大小"""
    totalsize = 0
    flist = os.listdir(filepath)
    for file in flist:
        fpath = os.path.join(filepath, file)
        if os.path.isdir(fpath):
            size = getfilesize(fpath)
            totalsize += size
        else:
            totalsize += os.path.getsize(fpath)
    return totalsize

filepath = 'F:\【3】数据分析\【4】hive'
sz = getfilesize(filepath)
if 0 <= sz <= 1024:
    filesize = sz / 1024
    print("此文件大小为：%.2f B" % filesize)
elif 1024 < sz <= 2048:
    filesize = sz / (1024*1024)
    print("此文件大小为：%.2f MB" % filesize)
else:
    filesize = sz / (1024*1024*1024)
    print("此文件大小为：%.2f GB" % filesize)




